package com.fengye.webflux.mongo.controller;

import com.fengye.webflux.model.Product;
import com.fengye.webflux.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 *
 * @author sky
 * @date 2021年05月28日 3:02 下午
 */
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    @GetMapping("")
    public Flux<Product> getProducts() {
        return this.productService.getProducts();
    }


    @GetMapping("/{id}")
    public Mono<Product> getProductsById(@PathVariable String id) {
        return this.productService.getProductsById(id);
    }

    @PostMapping("")
    public Mono<Void> createOrUpdateProduct(@RequestBody final Mono<Product> productMono) {
        return this.productService.createOrUpdateProduct(productMono);
    }

    @DeleteMapping("/{id}")
    public Mono<Product> deleteProduct(@PathVariable final String id) {
        return this.productService.deleteProduct(id);
    }
}
